package demo1;

public class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                '}';
    }

    public static void main(String[] args) {
        Student s1=new Student("dzj",20);
        Student s2=new Student("hzp",50);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s1.compareTo(s2));
        NameComparator nameComparator=new NameComparator();
        System.out.println(nameComparator.compare(s1, s2));
    }

    @Override
    public int compareTo(Student o) {
        if(this.age>o.age){
            return 1;
        }else if(this.age==o.age){
            return 0;
        }else{
            return -1;
        }
    }
}
